<?php

namespace common\util;

use stdClass;

class WsClient {

    public static function getInfo($token, $appId) {
        $params = ["token" => $token, "appId" => $appId];
        return self::call($params);
    }

    public static function call($params) {
        $request = new stdClass();
        $request->email = "bapcai.vn29@gmail.com";
        $request->code = "4d4d765e2c9302d0ffeca5e878d5a2be";
        $request->params = base64_encode(json_encode($params));

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "http://backend.passport.vn/wspassport/rest/public/api/get.api");
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        $result = curl_exec($ch);
        curl_close($ch);
        return json_decode($result);
    }

}
